﻿using System;
using Player;
using UnityEngine;


public class EquipWeaponComp : MonoBehaviour
{
    private BackpackComp backpackComp;

    private void Awake()
    {
        backpackComp = GetComponent<BackpackComp>();
    }

    public void EquipWeapon()
    {
        if (backpackComp.weaponList.Count > 0)
        {
            WeaponInstanceData weaponInstanceData = backpackComp.weaponList[0];
            backpackComp.weaponList.RemoveAt(0);
            // spawn 武器
            GameObject weaponInstance =
                Instantiate(
                    WeaponPrefabsManager.Instance.weaponPrefabs.Find(x => x.name == weaponInstanceData.prefabId));
            // 调用武器的equip 函数
            weaponInstance.GetComponent<WeaponEquipCompAbstr>().Equip(gameObject);
        }
    }

    private void Update()
    {
        // E装备武器
        if (Input.GetKeyDown(KeyCode.E))
        {
            EquipWeapon();
        }
    }
}